package cn.tongji.edu.tjmobile;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class WechatActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wechat_layout);

        ImageView icBackView = (ImageView) findViewById(R.id.image_ic_back);
        icBackView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread () {
                    public void run () {
                        try {
                            Instrumentation inst = new Instrumentation();
                            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                }.start();
            }
        });

        Intent intent = getIntent();
        MainActivity.CurrentActionSheet selection = ( MainActivity.CurrentActionSheet) intent.getSerializableExtra("qrcode_image");
        String wechatDescription = intent.getStringExtra("wechat_description");
        String wechatId = intent.getStringExtra("wechat_id");

        ImageView qrcodeImageView = (ImageView) findViewById(R.id.qrcode_source_image);
        switch (selection){
            case MOBILE_LIBRARY:
                qrcodeImageView.setImageResource(R.drawable.mobile_library_qrcode);
                break;
            case SCHOOL_FRIEND:
                qrcodeImageView.setImageResource(R.drawable.school_friend_qrcode);
                break;
            case YOUTH_TONGJI:
                qrcodeImageView.setImageResource(R.drawable.youth_tongji_qrcode);
                break;
        }

        TextView wechatDescriptionTextView = (TextView) findViewById(R.id.wechat_description);
        wechatDescriptionTextView.setText(wechatDescription);

        TextView wechatIdTextView = (TextView) findViewById(R.id.wechat_id);
        wechatIdTextView.setText(wechatId);
    }
}
